package com.net.tkc.pro.tool;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import org.springframework.stereotype.Component;

//@Component//注入到框架
public class DingTalkTool {
//    String KeyWorld="移动应用专业测试推送";//钉钉系统关键字，钉钉识别到关键字，就会推送
//    String DingTalkToken="0da8403e72bb3724ad1700e7c70061511176378374f4830cb88dc1138a543868";//Token
//    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token="+DingTalkToken);//钉钉群Token
//    OapiRobotSendRequest request = new OapiRobotSendRequest();//发送对象
//
//    /**
//     * 钉钉 发送简易消息
//     * @param Message 消息内容
//     * @return boolean
//     */
//    public boolean SendMessage(String Message){
//        boolean flag = true;
//        try{
//            request.setMsgtype("text");//发送消息类型
//            OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();//新建消息对象
//            text.setContent(KeyWorld+Message);//组成消息内容
//            request.setText(Message);
//            OapiRobotSendResponse response= client.execute(request);//推送
//            System.out.println("推送成功！");
//        }catch (Exception e){
//            e.printStackTrace();
//            flag=false;
//        }
//        return flag;
//    }
//    /**
//     * 钉钉群发模板消息
//     * @param MessageURL 原文链接
//     * @param PicURL 图片地址
//     * @param Title 标题
//     * @param Text 内容
//     * @return bool:True 发送成功，False 发送失败
//     */
//    public Boolean SendMessage(String MessageURL,String PicURL,String Title,String Text) {
//        try {
//            request.setMsgtype("link");
//            OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();//链接推送
//            link.setMessageUrl(MessageURL);//原文地址
//            link.setPicUrl(PicURL);//图片地址
//            link.setTitle(Title);//标题
//            link.setText(KeyWorld+Text);//内容
//            request.setLink(link);
//            System.out.println("发送成功");
//            OapiRobotSendResponse response = client.execute(request);
//            return true;
//        }catch (Exception e) {
//            e.printStackTrace();
//            return false;
//        }
//    }
}
